import pymysql
class DB:
    #初始化
    def __init__(self):
        # 连接数据库
        self.conn=pymysql.connect(host='localhost',port=3306,user='root',password='root',db='flaskku1',charset='utf8',cursorclass=pymysql.cursors.DictCursor)
        # 创建游标
        self.coursor=self.conn.cursor()
    # 查找所有
    def findall(self,sql):
        self.coursor.execute(sql)
        return self.coursor.fetchall()

    # 查找单个
    def findone(self,sql):
        self.coursor.execute(sql)
        return self.coursor.fetchone()

    # 添加
    def insert(self,sql):
        self.coursor.execute(sql)
        self.conn.commit()

    # 关闭
    def close(self):
        self.coursor.close()
        self.conn.close()
db=DB()